﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XStudio.XCRF.Data.Business;
using XStudio.XCRF.Web.Common.Sessions;
using XStudio.XCRF.Data.Enums;
using XStudio.XCRF.Data;

namespace XStudio.XCRF.Web.Controllers
{
    /// <summary>
    /// 控制器基类
    /// </summary>
    public abstract partial class BaseController : ExtendedController
    {
        private XCRFContext _DataContext;
        /// <summary>
        /// 获取数据访问上下文
        /// </summary>
        public XCRFContext DataContext
        {
            get
            {
                if (_DataContext == null)
                {
                    _DataContext = new XCRFContext();
                    if (LoginID != null)
                        _DataContext.SetCurrentMember((Guid)LoginID);
                }
                return _DataContext;
            }
        }
        /// <summary>
        /// 获取是否已登陆
        /// </summary>
        public static bool IsLoggedIn { get { return LoginSession.IsLoggedIn; } }
        /// <summary>
        /// 获取当前登录ID
        /// </summary>
        public static Guid? LoginID {get { return LoginSession.LoginID; } }
        /// <summary>
        /// 获取当前登陆用户名
        /// </summary>
        public static string LoginName { get { return LoginSession.LoginName; } }
        /// <summary>
        /// 获取登陆用户医院ID
        /// </summary>
        public static Guid? HospitalID { get { return LoginSession.HospitalID; } }
        //public static Guid CRFHospitalID { get; set; }
        /// <summary>
        /// 获取登陆用户的用户类型
        /// </summary>
        public static MemberTypes? LoginType { get { return LoginSession.MemberType; } }
        /// <summary>
        /// 获取用户是否是第一次登陆
        /// </summary>
        public static bool IsMemberFirst { get { return LoginSession.IsMemberFirst; } }
        /// <summary>
        /// 获取医院是否是第一次登陆
        /// </summary>
        public bool IsHospitalFirst { get { return LoginSession.IsHospitalFirst; } }
    }
}
